<template>
    <div>
        <Row>
            <Col span="24"
                <Alert show-icon>
                    操作说明
                    <Icon type="ios-bulb-outline" slot="icon"></Icon>
                    <template slot="desc">
                        <alertcontent :content = "content"></alertcontent>
                    </template>
                </Alert>
        </Col>
        </Row>
        <Row>
            <Col span="12">
                <Form :model="baseform" label-position="right" :label-width="150">
                    <FormItem label="代理ID：" style="margin-bottom:0px;">
                        <Input v-model="baseform.aiAid" disabled></Input>
                        <p>* 后台获取，第一修改</p>
                    </FormItem>
                    <FormItem label="代理编码：" style="margin-bottom:0px;">
                        <Input v-model="baseform.aiAcode" disabled></Input>
                        <p>* 后台获取，第一修改</p>
                    </FormItem>
                    <FormItem label="代理秘钥：">
                        <Input v-model="baseform.aiMidkey" disabled></Input>
                    </FormItem>
                    <FormItem label="通道地址：">
                        <Input v-model="baseform.aiMidurl" disabled></Input>
                    </FormItem>
                    <FormItem label="系统版本：">
                        <Input v-model="baseform.aiVersion" disabled></Input>
                    </FormItem>
                    <FormItem label="自动处理时间：" style="margin-bottom:0px;">
                        <InputNumber :min="3600" v-model="baseform.aiTime" disabled></InputNumber>
                        <p>* 单位为秒，最小为3600秒</p>
                    </FormItem>
                    <FormItem label="获取远程处理数据条数：" style="margin-bottom:0px;" >
                        <InputNumber :min="0" v-model="baseform.aiNum" disabled></InputNumber>
                        <p>* 远程数据条数不能小于0</p>
                    </FormItem>
                    <FormItem label="分润代付最小金额：" style="margin-bottom:0px;">
                        <InputNumber :min="10" v-model="baseform.aiSharePay"></InputNumber>
                        <p>* 分润代付最小金额不能小于10元，单位元</p>
                    </FormItem>
                    <FormItem label="系统名称：">
                        <Input v-model="baseform.aiAname"></Input>
                    </FormItem>
                    <FormItem label="备注：">
                        <Input v-model="baseform.aiRemark"></Input>
                    </FormItem>
                    <FormItem style="text-indent:50px;">
                        <Button @click="savebasesetting" type="primary" :disabled="accessSet">保存</Button>
                    </FormItem>
                </Form>
        </Col>
        </Row>
    </div>
</template>
<script>
import alertcontent from '_c/alertcontent/alertcontent'
import { getConfig, setConfig } from '@/api/data'
import { getAuthkey, getAccess } from '@/libs/util'
export default {
    name: 'basesetting',
    data() {
        return {
            baseform:{
                aiRemark: '',
                aiAname: '',
                aiSharePay: 10,
                aiNum: 0,
                aiTime: 3600,
                aiVersion: '',
                aiMidurl: '',
                aiMidkey: '',
                aiAcode: '',
                aiAid: '',
            },
            accessSet: true,
            content:[
                '每月只可以修改一次', 
                '加密参数配置', 
                '结算卡银行 只支持 5大行9小行', 
                '5大行: 工行,农行,中行,建行,交行', 
                '9小行: 招商，浦发，中信，华夏，光大，兴业，广发，民生，平安', 
                '注：1代理ID跟代理编码同时输入数值才可以获得图片设置代理邀请码跟代理二维码'
            ]
        }
    },
    components: {
        alertcontent
    },
    created() {
        this.accessSet = this.setBtnStatus()
        this.getsetting();
    },
    methods: {
        setBtnStatus: function(){
            let access = getAccess()
            if(access.length == 0){
                return true
            } else if (access.indexOf('admin') ==-1) {
                return true
            }else{
                return false
            }
        },
        savebasesetting: function() {
            let data = {
                aiSharePay: this.baseform.aiSharePay,
                aiAname: this.baseform.aiAname,
                aiRemark: this.baseform.aiRemark
            }
            let reqdata = {
                auth_key: getAuthkey(),
                eidtconfig: JSON.stringify(data)
            }
            setConfig(reqdata).then(res => {
                if(res.data.code !== 200){
                    this.$Message.error(res.data.error)
                    return
                }
                this.$Message.success('配置保存成功')
                this.getsetting()
            }, err => {
                this.$Message.error(err?err: '保存基础设置失败')
            })
        },
        getsetting: function() {
            let data = { auth_key: getAuthkey() }
            getConfig(data).then(res => {
                if(res.data.code !== 200){
                    this.$Message.error(res.data.error)
                    return
                }
                res.data.data.aiNum = parseInt(res.data.data.aiNum)
                res.data.data.aiTime = parseInt(res.data.data.aiTime)
                res.data.data.aiSharePay = parseInt(res.data.data.aiSharePay)
                this.baseform = res.data.data
            }, err => {
                this.$Message.error(err?err: '获取配置信息失败')
            })
        }
    }
}
</script>
